package com.gfl.trivialrestclient.dao;

import java.io.Serializable;
import java.util.List;

/**
 * Generic DAO (Data Access Object) with common methods to CRUD POJOs.
 *
 * @param <E> entity type variable
 * @param <PK> the primary key for that type
 */
public interface GenericDao<E, PK extends Serializable> {

    /**
     * Make entity persisted
     *
     * @param newInstance
     * @return persisted entity
     */
    public E save(E newInstance);

    /**
     * Update already persisted entity with specified identifier or persist
     * transient entity
     *
     * @param entity
     * @return persisted entity
     */
    public E edit(E entity);

    public void delete(E persistentObject);

    /**
     * Get entity based on it identifier.
     *
     * @param pk - id of entity
     * @return finded peristed entity or null if entity with such id not exists
     */
    public E findById(PK pk);

    public List<E> findAll();

    /**
     * Calculate number of entities
     *
     * @return
     */
    public long countAll();
}
